package com.justnow.offer.q1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * newSingleThreadExecutor单线程化线程池，串行执行任务。保证所有任务的执行顺序按照任务的提交顺序执行。
 */
public class ThreadPoolDemo {
    static ExecutorService threadPool = null;

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            threadPool = Executors.newSingleThreadExecutor();
            Thread t1 = new Thread(() -> {
                System.out.println("产品经理规划新需求");
            });
            Thread t2 = new Thread(() -> {
                System.out.println("开发人员开发新需求功能");
            });
            Thread t3 = new Thread(() -> {
                System.out.println("测试人员测试新功能");
            });
            threadPool.submit(t1);
            threadPool.submit(t2);
            threadPool.submit(t3);
            threadPool.shutdown();
        }

    }
}
